﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.Live.ServerControls.VE.Constants;

[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.SetMapMode.js", "text/javascript")]
[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.SetMapMode.debug.js", "text/javascript")]

namespace Microsoft.Live.ServerControls.VE.Extenders
{
    [ToolboxData(@"<{0}:SetMapMode ID=""SetMapModeExtender1"" runat=""server"" MapMode=""Mode2D"" MapControlID="""" TargetControlID="""" ></{0}:SetMapMode>")]
    public sealed class SetMapMode : ExtenderBase
    {

        #region Properties

        /// <summary>
        /// A VEMapMode Enumeration value specifying the map mode
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [DefaultValue(MapMode.Mode2D)]
        [Description("A VEMapMode Enumeration value specifying the map mode")]
        public MapMode MapMode 
        {
            get
            {
                if (ViewState[SetMapModeExtenderControlProperty.MapMode] != null)
                {
                    return (MapMode)ViewState[SetMapModeExtenderControlProperty.MapMode];
                }
                else
                {
                    return MapMode.Mode2D;
                }
            }
            set { ViewState[SetMapModeExtenderControlProperty.MapMode] = value; } 
        }

        #endregion

        #region ExtenderControl Members

        protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(Control targetControl)
        {
            ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor("Microsoft.Live.ClientControls.VE.Extenders.SetMapMode", targetControl.ClientID);
            descriptor.AddProperty(SetMapModeExtenderControlProperty.MapMode, MapMode);
            descriptor.AddProperty(ExtenderControlProperty.MapControlID, MapControlID);
            yield return descriptor;
        }

        protected override IEnumerable<ScriptReference> GetScriptReferences()
        {
            List<ScriptReference> descriptors = new List<ScriptReference>();
            descriptors.Add(new ScriptReference("Microsoft.Live.ServerControls.VE.Extenders.SetMapMode.js", GetType().Assembly.FullName));
            return descriptors;
        }

        #endregion
    }
}
